package com.example.studentalarm.presenter;

import android.content.Context;

import com.example.studentalarm.database.DbManager;


public abstract class BasePresenter<T> {

    /**
     * View的弱引用
     */
    protected T mViewRef;
    protected Context mContext;

    public BasePresenter(Context mContext) {
        this.mContext=mContext;
        DbManager.getInstance().onInit(mContext);
    }


    public void attach(T mView) {
        this.mViewRef=mView;

    }

    public void detachView() {
        if (mViewRef != null) {
            mViewRef=null;
        }
        DbManager.getInstance().closeDB();
    }
    /**
     * View是否绑定
     *
     * @return
     */
    public boolean isViewAttached() {
        return mViewRef != null;
    }

    /**
     * 得到VIew
     *
     * @return
     */
    protected T getView() {
        return mViewRef;
    }
}
